#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct caa
{
    int pos1, pos2;
    long long tiredness;
} Carry;

vector<long long> weight;
vector<Carry> solution;

bool cmp(Carry a, Carry b)
{
    return a.tiredness < b.tiredness;
}

bool cmp2(long long a, long long b)
{
    return a < b;
}

long long tired(int a, int b)
{
    return (weight[a] - weight[b]) * (weight[a] - weight[b]);
}

int main()
{
    ios::sync_with_stdio(false);
    int n, k, i, j, tmp;
    long long pld = 0; //疲劳度
    Carry onecarry;
    while (cin >> n >> k)
    {
        pld = 0;
        weight.clear();
        solution.clear();
        for (i = 0; i < n; i++)
        {
            cin >> tmp;
            weight.push_back(tmp);
        }
        sort(weight.begin(), weight.end(), cmp2);
        onecarry.pos1 = 0;
        onecarry.pos2 = 1;
        onecarry.tiredness = tired(0, 1);
        solution.push_back(onecarry);
        for (i = 2; i < n - 1; i++)
        {
            if (tired(i, i + 1) + tired(i - 1, i - 2) <= tired(i - 2, i + 1) + tired(i - 1, i))
            {
                onecarry.pos1 = i;
                onecarry.pos2 = i + 1;
                onecarry.tiredness = tired(i, i + 1);
                solution.push_back(onecarry);
                i++;
            }
            else
            {
                solution.back().pos1 = i - 1;
                solution.back().pos2 = i;
                onecarry.pos1 = i - 2;
                onecarry.pos2 = i + 1;
                onecarry.tiredness = tired(i - 2, i + 1);
                solution.push_back(onecarry);
            }
        }
        sort(solution.begin(), solution.end(), cmp);
        for (i = 0; i < k; i++)
        {
            pld += solution[i].tiredness;
        }
        cout << pld << endl;
    }
}